package com.zenq.ssm.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zenq.ssm.entity.User;
import com.zenq.ssm.mapper.UserMapper;

// Spring会把使用Service注解标注的类，当做一个Service组件来进行处理。
@Service
public class UserService {
	// 根据类型进行匹配
	@Autowired
	private UserMapper userMapper;
	/**
	 * 用户登录
	 * @param loginUser
	 * @return
	 */
	public User login(User loginUser) {
		User user = userMapper.selectByUsername(loginUser.getUsername());
		if (user != null) {
			if (user.getPassword().equals(loginUser.getPassword())) {
				return user;
			}
		}
		return null;
	}
	
	// 用户注册
	public boolean regist(User user) {
		// 可能有其他业务逻辑....如验证，用户名已经存在验证.....
		int result = userMapper.insert(user);
		return result > 0;
	}
	/**
	 * 修改用户密码
	 * @param user
	 * @return
	 */
	public boolean updatePassword(User user) {
		int result = userMapper.updateByPrimaryKeySelective(user);
		return result > 0;
	}
}
